







//
//  NConfirmPopView.m
//  PPShareView
//
//  Created by macfai on 2018/9/29.
//  Copyright © 2018年 pengpeng. All rights reserved.
//

#import "NConfirmPopView.h"
#import "Masonry.h"
#import "UIView+Sizes.h"
#define kSCREENWIDTH     [UIScreen mainScreen].bounds.size.width
#define kSCREENHEIGHT    [UIScreen mainScreen].bounds.size.height
#define kViewHeight 160

@interface NConfirmPopView()

@property(nonatomic,strong)UIView *bottomBgView;

@end


@implementation NConfirmPopView

- (instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
//        self.frame = frame;
        self.frame = [UIScreen mainScreen].bounds;
        self.backgroundColor = [[UIColor lightGrayColor]colorWithAlphaComponent:0.5];
        [self setUI];
    }
    return self;
}

- (void)setUI {
    
    self.bottomBgView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight, ScreenWidth, kViewHeight)];
    self.bottomBgView.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0];
    [self addSubview:self.bottomBgView];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, kSCREENWIDTH, 40)];
    label.centerX = self.centerX;
    label.text =@"反馈问题已得到解答，确认提问将关闭 \n 已答复问题3天后自动确认关闭";
    label.numberOfLines = 0;
    label.textColor = [UIColor darkGrayColor];
    label.font = [UIFont systemFontOfSize:15];
//    label.backgroundColor = [UIColor magentaColor];
    
    label.textAlignment = NSTextAlignmentCenter;
    [self.bottomBgView addSubview:label];
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 90, 300, 50);
    btn.centerX = self.centerX;
    [btn addTarget:self action:@selector(tapActoin:) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.cornerRadius = 8.f;
    btn.layer.masksToBounds = YES;
    [btn setTitle:@"确认问题已解答" forState:UIControlStateNormal];
    btn.backgroundColor =  NColorFrom16RGB(0x23b7e5);
    [self.bottomBgView addSubview:btn];
    
//    [label mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.bottomBgView.mas_left).offset();
//    }];
    
}

-(void)setButtonClick:(ConfirmBtnClick)buttonClick{
    _buttonClick = buttonClick;
}


- (void)tapActoin:(UIButton *)btn
{
    
    if (self.buttonClick) {
        self.buttonClick(btn);
    }
    [self dismiss];
    
}


-(void)show{
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    [UIView animateWithDuration:.3 animations:^{
        if (kSCREENWIDTH>320) {
            self.bottomBgView.transform = CGAffineTransformMakeTranslation(0,  - kViewHeight);
        }else{
            self.bottomBgView.transform=  CGAffineTransformMakeTranslation(0, -160);
        }
        
    }];
}

-(void)dismiss{
    
    [UIView animateWithDuration:0.3 animations:^{
        
        self.bottomBgView.transform = CGAffineTransformIdentity;
        
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [super touchesBegan:touches withEvent:event];
    [self dismiss];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
